package leecode
func LengthOfLongestSubstring(s string) int {
	var m =make(map[uint8]int)
	if len(s)<2{
		return len(s)
	}
	var old int
	var cur int
	for i:=0;i<len(s);i++{
		if v,ok:=m[s[i]];ok{
			if old<cur{
				old=cur
			}
			Delete(m,s,m[s[i]],i)
			cur=i-v
			continue
		}
		cur ++
		m[s[i]]=i
	}
	if cur>old{
		return cur
	}
	return old
}

func Delete(m map[uint8]int,s string,i ,v int){
	for i:=range m{
		delete(m,i)
	}
	for t,u:=range s[i+1:v+1]{
		m[uint8(u)]=t+i+1
	}
}